import type { App } from 'vue'
// 需要全局引入一些组件，如ElScrollbar，不然一些下拉项样式有问题
import { ElLoading, ElScrollbar, ElButton, ElSelect } from 'element-plus'

import * as ElementIcons from '@element-plus/icons-vue'

const plugins = [ElLoading]
// 👇使用 form-create 需额外全局引入 element plus 组件
const components = [
  ElScrollbar,
  ElButton,
  ElSelect,
  ElOption,
  ElAside,
  ElPopconfirm,
  ElHeader,
  ElMain,
  ElContainer,
  ElDivider,
  ElTransfer,
  ElAlert,
  ElTabs,
  ElTable,
  ElTableColumn,
  ElTabPane,
]

export const setupElementPlus = (app: App<Element>) => {
  plugins.forEach((plugin) => {
    app.use(plugin)
  })

  components.forEach((component: any) => {
    app.component(component.name, component)
  })

  for (const key in ElementIcons) {
    const componentConfig = ElementIcons[key]
    app.component(componentConfig.name, componentConfig)
  }
}
